package com.wbc.smartHome.web;

import com.github.pagehelper.PageInfo;
import com.wbc.smartHome.model.LiveTV;
import com.wbc.smartHome.model.Result;
import com.wbc.smartHome.service.LiveTVService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.IOException;


@RestController
@RequestMapping(path = "/api/liveTVCtl")
/*直播存储获取*/
@Api(tags = "直播模块")
public class LiveTVController {


    @Autowired
    private LiveTVService liveTVService;

    @ApiOperation("获取所有直播详细信息")
    @ApiResponses({
            @ApiResponse(code = 200 , message = "OK"),
            @ApiResponse(code = 500 , message = "系统异常")
    })
    @PostMapping(path = "getLiveTVList")
    public Result getLiveTVList(@RequestBody LiveTV liveTV) {
        PageInfo<LiveTV> liveTVList = liveTVService.getLiveTVList(liveTV);
        return new Result(200, "OK", liveTVList);
    }

    @ApiOperation("添加直播")
    @ApiResponses({
            @ApiResponse(code = 200 , message = "OK"),
            @ApiResponse(code = 500 , message = "系统异常")
    })
    @PostMapping(path = "setLiveTVList")
    public Result setLiveTVList(@RequestBody LiveTV liveTV,@RequestHeader("adminToken") String adminToken) {
        if (liveTV.getId()==null){
            liveTVService.setLiveTV(liveTV,adminToken);
        }
        else {
            liveTVService.updateLiveTV(liveTV,adminToken);
        }
        return new Result(200,"ok",null);
    }

    @ApiOperation("上传类型封面图")
    @PostMapping("/uploadImg")
    public Result uploadImg(@RequestParam("file") CommonsMultipartFile commonsMultipartFile) throws IOException {
        Result result = liveTVService.uploadImg(commonsMultipartFile);
        return  result;
    }

    @ApiOperation("删除直播")
    @ApiResponses({
            @ApiResponse(code = 200 , message = "OK"),
            @ApiResponse(code = 500 , message = "系统异常")
    })
    @GetMapping(path = "delete")
    public Result delete(int id){
        liveTVService.delete(id);
        return new Result(200,"ok",null);
    }
    @ApiOperation("按照id获取直播")
    @ApiResponses({
            @ApiResponse(code = 200 , message = "OK"),
            @ApiResponse(code = 500 , message = "系统异常")
    })
    @GetMapping(path = "getLiveTVByid")
    public Result getLiveTVByid(int id) {
        LiveTV liveTV = liveTVService.getLiveTVById(id);
        return new Result(200,"OK",liveTV);
    }

}
